import json
from datetime import datetime

from mqtt.method.control_fly_method import ControlFlyMethodEnum
from mqtt.callback.callback_manager import callbackManager
"""
    调用指令飞行相关的回调
"""
class ServicesReplyCallbackHandler(callbackManager):
    def handle(self, payload):
        data = json.loads(payload)
        method = data['method']
        now = datetime.now()
        log_time = now.strftime('%Y-%m-%d %H:%M:%S')
        message = ""
        if method == ControlFlyMethodEnum.CLOUD_CONTROL_AUTH_REQUEST.get_method():
            message = "请求授权云端控制响应"
        elif method == ControlFlyMethodEnum.CLOUD_CONTROL_RELEASE.get_method():
            message = "释放云端控制响应"
        elif method == ControlFlyMethodEnum.DRC_MODE_ENTER.get_method():
            message = "进入指令飞行控制模式响应"
        elif method == ControlFlyMethodEnum.DRC_MODE_EXIT.get_method():
            message = "退出指令飞行控制模式响应"
        elif method == ControlFlyMethodEnum.TAKEOFF_TO_POINT.get_method():
            message = "一键起飞响应"
        elif method == ControlFlyMethodEnum.FLY_TO_POINT.get_method():
            message = "飞向目标点响应"
        elif method == ControlFlyMethodEnum.FLY_TO_POINT_STOP.get_method():
            message = "飞向目标点任务响应"
        elif method == ControlFlyMethodEnum.FLY_TO_POINT_UPDATE.get_method():
            message = "更新 flyto 目标点响应"
        elif method == ControlFlyMethodEnum.RETURN_HOME.get_method():
            message = "一键返航响应"
        elif method == ControlFlyMethodEnum.RETURN_HOME_CANCEL.get_method():
            message = "取消一键返航响应"
        print(message)
        print(data['data'])
        self.publish_callback_message(f"{log_time}_{message}:{payload}")

